package com.maiikun.aqs;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Main {
    public static void main(String[] args) throws InterruptedException {
//        Lock lock = new ReentrantLock();
        MyLock lock = new MyLock();
        int[] nums = new int[]{1000};

        List<Thread> threadList = new ArrayList<>(10);
        for (int i = 0; i < 10; i++) {
            threadList.add(new Thread(() -> {
                lock.lock();
                lock.lock();
                for (int j = 0; j < 100; j++) {
                    nums[0]--;
                }
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                lock.unlock();
                lock.unlock();
            }));
        }

        for (Thread thread : threadList) {
            thread.start();
        }

        for (Thread thread : threadList) {
            thread.join();
        }

        System.out.println("主线程结束 - nums[0]->" + nums[0]);


    }
}
